package com.hangzhou.xyj.ui.activity;

import android.content.Intent;
import android.support.v4.view.ViewPager;
import android.view.View;

import com.hangzhou.xyj.R;
import com.hangzhou.xyj.ui.activity.base.BaseActivity;
import com.hangzhou.xyj.ui.adapter.PhotoViewAdapter;
import com.hangzhou.xyj.ui.widget.views.MyImageView;
import com.hangzhou.xyj.ui.widget.views.MyTextView;
import com.hangzhou.xyj.utils.constants.DataKey;

import java.util.List;

/**
 * @author : neo.duan
 * @date : 	 2016/4/3
 * @desc :
 */
public class PhotoViewActivity extends BaseActivity {

    private ViewPager mViewPager;
    private List<String> mImageList;
    private PhotoViewAdapter mAdapter;
    private MyTextView mTvIndicator;// 图片张数指示器
    private int mInitIndex; //初始化第几张被选中
    private MyImageView mIvBack;//返回按钮

    @Override
    public void initIntentData(Intent intent) {
        super.initIntentData(intent);
        if (intent == null) {
            return;
        }
        mImageList = intent.getStringArrayListExtra(DataKey.IMAGE_LIST);
        mInitIndex = intent.getIntExtra(DataKey.INDEX, -1);
    }

    @Override
    public void initTop() {
        enableTop(false);
    }

    @Override
    public void initLayouts() {
        setContentView(R.layout.activity_photo_view);
    }

    @Override
    public void initViews() {
        mViewPager = findView(R.id.view_pager);
        mTvIndicator = findView(R.id.mtv_indicator);
        mIvBack = findView(R.id.miv_back);
        mViewPager.setAdapter(mAdapter = new PhotoViewAdapter(this, mImageList));
        mViewPager.setCurrentItem(mInitIndex);
        mTvIndicator.setText("" + (mInitIndex + 1) + "/" + mImageList.size());
        mViewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                mTvIndicator.setText("" + (position + 1) + "/" + mImageList.size());
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });
    }

    @Override
    public void initDatas() {

    }

    @Override
    public void initListeners() {
        //photoView点击
        mAdapter.setOnPhotoViewClickListener(new PhotoViewAdapter.OnPhotoViewClickListener() {
            @Override
            public void onPhotoClick(View view) {
                closeActivity();
            }
        });
        mIvBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                closeActivity();
            }
        });
    }
}
